package ch15;

import java.util.Scanner;
import java.lang.Integer;

/**
 * Created by zhangyunqi on 2017/10/21.
 */
public class Pascal {
    public static void main(String args[]) {
        CircularArrayQueue <Integer> queue = new CircularArrayQueue <Integer> ();
        System.out.println ( "1.请输入杨辉三角打印行数（循环队列）：" );
        Scanner scanner = new Scanner ( System.in );
        int a = scanner.nextInt ();
        System.out.println ( "循环队列杨辉三角：" );
        queue.enqueue ( 0 );
        queue.enqueue ( 1 );
        int i = 0;
        while (i <= a) {
            int x = queue.dequeue ();
            int y = queue.frontqueue ();
            if (x == 0) {
                i++;
                queue.enqueue ( 0 );
                System.out.println ();
                for (int j = 0; j < 2 * (a - i); j++)
                    System.out.print ( " " );
            } else
                System.out.print ( x + "   " );

            queue.enqueue ( x + y );
        }

//https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=0&rsv_idx=1&tn=
// baidu&wd=%E6%9D%A8%E8%BE%89%E4%B8%89%E8%A7%92%20%E5%BE%AA%E
// 7%8E%AF%E9%98%9F%E5%88%97java&rsv_pq=af8013db000112b6&rsv_t
// =5da6uA5vbWmtDW2DK912C3o%2BzDe78X949%2B5nrKDtx1QtqyOfcFlMrg4Yc90&rqlang=cn&rsv_enter
// =1&rsv_sug3=32&rsv_sug1=16&rsv_sug7=100&rsv_sug2=0&inputT=11641&rsv_sug4=12740
        System.out.println ( " " );

        System.out.println ( "2.请输入杨辉三角打印行数（非循环队列）：" );
        Scanner sca = new Scanner ( System.in );
        int line = sca.nextInt ();
        System.out.println ( " " );
        System.out.println ( "不用循环队列的杨辉三角：" );
        int e[][];
        e = new int[line][];
        for (
                int q = 1;
                q <= line; q++)

        {
            e[q - 1] = new int[q];
        }
        for (
                int w = 0;
                w < line; w++)

        {
            for (int k = 0; k <= w; k++) {
                if (w == 0 || k == 0 || k == w)// 分支
                {
                    e[w][k] = 1;// 等于1的
                    continue;
                } else {
                    e[w][k] = e[w - 1][k - 1] + e[w - 1][k];// 计算值
                }
            }
        }
        for (
                int m = 0;
                m < line; m++)

        {
            for (int n = 0; n <= m; n++) {
                System.out.print ( "" + e[m][n] + " " );// 循环输出
            }
            System.out.println ( " " );
        }
    }


}
